layui.config({
    base: "../../js/"
}).extend({
    "jqCommon": "jqCommon"
})
layui.use(['form', 'layer', 'table', 'laytpl', 'jqCommon'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table;
    jqcommon = layui.jqCommon;

    //用户列表
    var tableIns = table.render({
        elem: '#inviteList',
        url: 'http://mini.yantaibaixing.cn/users',
        where: {userId: $(".userId").val()}, //如果无需传递额外参数，可不加该参数
        method: 'get', //如果无需自定义HTTP类型，可不加该参数
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 200 //成功的状态码，默认：0
            , msgName: 'message' //状态信息的字段名称，默认：msg
            , countName: 'total' //数据总数的字段名称，默认：count
            , dataName: 'datas' //数据列表的字段名称，默认：data
        },
        cellMinWidth: 95,
        page: true,
        height: "full-125",
        limits: [10, 15, 20, 25],
        limit: 20,
        id: "inviteListTable",
        cols: [[
            {field: 'name', title: '姓名', width: 130, align: "center"},
            {field: 'phone', title: '手机号', width: 130, align: "center"},
            {
                field: 'gender', title: '性别', width: 70, align: 'center', templet: function (d) {
                return d.gender == 1 ? "男" : "女";
            }
            },
            {
                field: 'type', title: '类型', width: 70, align: 'center', templet: function (d) {
                return d.type == 1 ? "个人" : "商户";
            }
            },
            {
                field: 'vipNo', title: '会员号', width: 130, align: 'center', templet: function (d) {
                if (d.vipNo == '无') {
                    return '无';
                } else {
                    return d.vipNoPrefix + d.vipNo;
                }
            }
            },
            {
                field: 'vipType', title: '会员类型', width: 110, align: 'center', templet: function (d) {
                if (d.vipType == 1) {
                    return "非会员";
                } else if (d.vipType == 2) {
                    return "商户会员";
                } else if (d.vipType == 3) {
                    return "付费会员";
                } else if (d.vipType == 4) {
                    return "赠送会员";
                }
            }
            },
            {field: 'shopName', title: '商户名称', align: "center"},
            {field: 'shopAdress', title: '商户地址', align: "center"}
        ]]
    });

    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").on("click", function () {
        var type = $("#type").val();
        var vipType = $("#vipType").val();
        var param = $(".searchVal").val();
        var userId = $(".userId").val();
        table.reload("inviteListTable", {
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                param: param,  //搜索的关键字
                type: type,
                vipType: vipType,
                userId: userId
            }
        })
    });
})
